package com.ewhale.feitengguest.presenter.user.message

import com.ewhale.feitengguest.api.ApiHelper
import com.ewhale.feitengguest.dto.HaveUnreadMsgDto
import com.ewhale.feitengguest.dto.ShopMessageDto
import com.ewhale.feitengguest.view.shop.message.SMessageView
import com.ewhale.feitengguest.view.user.message.MessageView
import com.simga.library.base.IPresenter
import com.simga.library.http.APIException

class MessagePresenter : IPresenter(){
    fun getMessageUnRead() {
        request(1, ApiHelper.MESSAGE_API.haveMessageUnRead(), null)
    }

    override fun <T> onNext(postCode: Int, result: T, data: Any?) {
        super.onNext(postCode, result, data)
        when (postCode) {
            1 -> {
                (mView as MessageView).haveMessageUnRead(result as HaveUnreadMsgDto)
            }
        }
    }

    override fun otherException(postCode: Int, data: Any, e: APIException?) {
        super.otherException(postCode, data, e)
        mView.showErrorMessage(postCode, e!!.code, e.displayMessage)
    }
}
